package com.wyh.controller;


import com.wyh.common.annotation.Log;
import com.wyh.common.annotation.RateLimiter;
import com.wyh.common.enums.BusinessType;
import com.wyh.common.response.PageInfo;
import com.wyh.common.result.R;
import com.wyh.common.util.ExcelUtils;
import com.wyh.entity.MsgRecontact;
import com.wyh.request.MsgRecontactRequest;
import com.wyh.service.IMsgRecontactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 联系人,非好友控制层
 *
 * @author WangYuHang
 * @date 2024-03-08
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "联系人,非好友接口管理",tags = "联系人,非好友接口管理")
@RequestMapping("/admin/msgRecontact" )
public class MsgRecontactController {

    private final IMsgRecontactService iMsgRecontactService;


    /**
     * 查询好友列表
     */
    @ApiOperation(value = "查询好友列表")
    @GetMapping("/friends")
    public R<List<MsgRecontact>> queryList() {
        R<List<MsgRecontact>> listR = iMsgRecontactService.queryList();
        return listR;
    }


    /**
     * 根据Id搜索好友
     */
    @ApiOperation(value = "根据Id搜索好友")
    @GetMapping("/{userId}")
    public R<MsgRecontact> queryOne(@PathVariable("userId") String userId) {
        R<List<MsgRecontact>> listR = iMsgRecontactService.queryList();
        return null;
    }

    /**
     * 删除好友
     */
    @ApiOperation(value = "删除好友")
    @GetMapping("/delete/{friendId}")
    public R<String> deleteOne(@PathVariable("friendId") String friendId) {
        R<String> stringR = iMsgRecontactService.deleteOne(friendId);
        return stringR;
    }

    /**
     * 修改备注
     */
    @ApiOperation(value = "修改备注")
    @GetMapping("/update/{friendId}/{remark}")
    public R<String> updateFriendRemark(@PathVariable("friendId") String friendId,@PathVariable("remark") String remark) {
        R<String> stringR = iMsgRecontactService.updateRemark(friendId, remark);
        return stringR;
    }




    /**
     * 分页查询联系人,非好友列表
     */
    @ApiOperation(value = "分页查询联系人,非好友列表")
    @PostMapping("/pageList")
    public R<PageInfo<MsgRecontact>> pageList(@RequestBody MsgRecontactRequest msgRecontactRequest) {
        return R.success(iMsgRecontactService.pageList(msgRecontactRequest));
    }

    /**
     * 获取联系人,非好友详细信息
     */
    @ApiOperation(value = "获取联系人,非好友详细信息")
    @GetMapping(value = "/query/{id}")
    public R<MsgRecontact> detail(@PathVariable("id") Integer id) {
        return R.success(iMsgRecontactService.getById(id));
    }

    /**
     * 新增联系人,非好友
     */
    @Log(title = "新增联系人,非好友", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增联系人,非好友")
    @PostMapping("/add")
    public R<Void> add(@RequestBody MsgRecontact msgRecontactRequest) {
        iMsgRecontactService.add(msgRecontactRequest);
        return R.success();
    }

    /**
     * 修改联系人,非好友
     */
    @Log(title = "修改联系人,非好友", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改联系人,非好友")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody MsgRecontactRequest msgRecontactRequest) {
        iMsgRecontactService.update(msgRecontactRequest);
        return R.success();
    }

    /**
     * 删除联系人,非好友
     */
    @Log(title = "删除联系人,非好友", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除联系人,非好友")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iMsgRecontactService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出联系人,非好友
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody MsgRecontactRequest msgRecontactRequest) throws IOException {
        List<MsgRecontact> list = iMsgRecontactService.list(msgRecontactRequest);
        ExcelUtils.exportExcel(list, MsgRecontact.class, "联系人,非好友信息", response);
    }
}
